package com.ruoyi.listener;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

import com.ruoyi.iotcommon.domain.CommandPostMessage;
import com.ruoyi.session.DeviceManager;

import jakarta.annotation.Resource;

/**
 * 监听iot-core服务下发的指令，转为设备指令
 */
@Service
@RocketMQMessageListener( topic = "iot-command-post-tcp", consumerGroup = "iot-transform-tcp")
public class CommandPostListener implements RocketMQListener<CommandPostMessage>{


    @Resource
    private DeviceManager deviceManager;

    @Override
    public void onMessage(CommandPostMessage message) {
        // TODO 转为为设备指令，下发给设备, 需要自己根据协议内容，将params中的数据转为设备字节，这里只是demo
        deviceManager.sendCommand(message.getDeviceKey(), message.getParams().toString().getBytes());
    }
    
}
